//
//  InformationTableViewCell.m
//  lsOA
//
//  Created by 蓝水软件 on 16/7/19.
//  Copyright © 2016年 苏州蓝水有限公司. All rights reserved.
//

#import "InformationTableViewCell.h"

@implementation InformationTableViewCell{
    UIImageView *imageView;
    UILabel *label;
    UILabel *messNum;
    UILabel *cntInfo;
}



- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        CGSize imageSize ;
        if (IS_IPHONE_4) {
            imageSize = CGSizeMake(35, 35);
        }else{
            imageSize = LRLCGSizeMake(35,35);
        }
        
        imageView = [[UIImageView alloc]init];
        [self.contentView addSubview:imageView];
        [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.contentView);
            make.left.mas_equalTo(15*FitSize);
            make.size.mas_equalTo(imageSize);
        }];
        
        UIImageView *rightimage = [[UIImageView alloc]init];
        [self.contentView addSubview:rightimage];
        rightimage.image = [UIImage imageNamed:@"right"];
        [rightimage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.contentView);
            make.right.mas_equalTo(-31);
            make.width.mas_equalTo(30);
            make.height.mas_equalTo(30);
        }];
        
        label = [[UILabel alloc]init];
        [self.contentView addSubview:label];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.contentView);
            make.left.equalTo(imageView.mas_right).offset(5*FitSize);
            make.width.mas_equalTo(FitSize*200);
        }];
        label.font = FONT(15);
        //未读数
        messNum = [[UILabel alloc]init];
        [self.contentView addSubview:messNum];
        [messNum mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(rightimage.mas_left).offset(-20);
            make.centerY.equalTo(self.contentView);
            make.width.mas_equalTo(FitSize * 30);
            make.height.mas_equalTo(FitSize * 14);
        }];
        messNum.textColor = [UIColor whiteColor];
        messNum.textAlignment = NSTextAlignmentCenter;
        messNum.font = FONT(10);
        messNum.backgroundColor = [UIColor colorWithRed:1.000 green:0.400 blue:0.400 alpha:1.000];
        messNum.layer.cornerRadius = FitSize*7;
        messNum.layer.masksToBounds = YES;
        
        cntInfo = [[UILabel alloc]init];
        cntInfo.textColor =  [UIColor whiteColor];
        cntInfo.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:cntInfo];
        [cntInfo mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(imageView.mas_left).offset(-20*FitSize);
            make.centerY.equalTo(self.contentView);
            make.width.mas_equalTo(500*FitSize);
            make.height.mas_equalTo(30*FitSize);
        }];
        cntInfo.layer.cornerRadius = 10;
        
        UIView *line = [[UIView alloc]init];
        [self.contentView addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(1);
            make.left.mas_equalTo(FitSize*15);
            make.right.mas_equalTo(FitSize*-15);
            make.bottom.mas_equalTo(-1);
        }];
        line.backgroundColor = [UIColor colorWithWhite:0.744 alpha:1.000];
    }
    return self;
}


//更新数据
- (void)setWithDic:(NSDictionary *)dic index:(NSInteger)row{
    NSString *imageName;
    if (row == 0) {
        imageName = dic[@"tableImageArray"][0];
    }else{
        imageName = dic[@"tableImageArray"][1];
    }
    imageView.image = [UIImage imageNamed:imageName];
    label.text = dic[@"tableLabelArray"][row];
    NSString *cntInfoString = dic[@"cntInfo"][row];
    if (cntInfoString.length <= 0  || [cntInfoString isEqualToString:@"0/0"]) {
        messNum.hidden = YES;
    }else if([[cntInfoString substringToIndex:2] isEqualToString:@"0/"]){
        messNum.hidden = NO;
        messNum.text = cntInfoString;
        messNum.backgroundColor = [UIColor colorWithRed:0.400 green:0.800 blue:1.000 alpha:1.000];
    }else{
        messNum.hidden = NO;
        messNum.text = cntInfoString;
        messNum.backgroundColor = [UIColor colorWithRed:1.000 green:0.400 blue:0.400 alpha:1.000];
    }
//    cntInfo.text = dic[@"cntInfo"][row];
}

@end
